namespace TimeSheet.Protected.View.Model
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	/// <summary>
	///		Summary description for ViewStaff.
	/// </summary>
	public abstract class ViewStaff : GridControl
	{
		protected eWorld.UI.EmptyDataGrid dgStaff;
		protected eWorld.UI.CollapsablePanel cpGrid;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if( !IsPostBack )
			{
				this.cpGrid.Collapsed = true;
			}
			this.Grid = this.dgStaff;
			this.BindTable();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.dgStaff.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgStaff_ItemCreated);
			this.dgStaff.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgStaff_DeleteCommand);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void dgStaff_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			switch( e.Item.ItemType )
			{
				case ListItemType.Item:
					Button but = (Button) e.Item.Cells[ 3 ].Controls[ 0 ];
					but.Attributes.Add( "onclick", "return confirm('Are you sure you want to delete this item?');" );
					
					break;
				case ListItemType.AlternatingItem:
					Button but2 = (Button) e.Item.Cells[ 3 ].Controls[ 0 ];
					but2.Attributes.Add( "onclick", "return confirm('Are you sure you want to delete this item?');" );
				
					break;
				case ListItemType.EditItem:
					Button but3 = (Button) e.Item.Cells[ 3 ].Controls[ 0 ];
					but3.Attributes.Add( "onclick", "return confirm('Are you sure you want to delete this item?');" );
				
					break;
			}
		}

		private void dgStaff_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			TimeSheetBLL.User user = new TimeSheetBLL.User();
			user.ID = Convert.ToInt64( e.Item.Cells[0].Text );

			TimeSheetBLL.BrokerFactory.Delete( user );

			Response.Redirect( "Staff.aspx" );
		}
	}
}
